Running Migrations from the NHibernate Designer
To run migrations from the NHibernate designer:
- Open your model.
- From the Migrations menu, choose Run Migrations. The Migrations window is displayed.
- The Migrations window shows the available migrations and the current database version. (If you see a “migrations project does not build” message, open the Errors window and fix the problems, then click Refresh to try again.)
- Check that the Method is set to Apply to connected database and that the database and connection string are correct. If not, choose Change to change your settings. (See below for more info.)
- Select the target version that you’d like to migrate the database to.
- Select Apply Now.
Choosing the Migration Target
Before you first run migrations, you need to choose the target database. To do this:
- Choose the Change button next to the database connection information.
- NHibernate Designer displays the Migration Settings wizard.
- Choose Apply migrations directly to a database and click Next.
- Either select a Server Explorer connection, or choose a database type and enter a connection string.
- Click Finish.
If you subsequently change the migration target, to run the migrations against a different database, choose the Change button again and re-run the wizard.
Running Migrations from the Command Line
To run migrations from the command line, run the nhmigrate.exe program. You can find this in your migration project, under the Runner folder. nhmigrate compiles migration source code files from the current directory. (In this case you do not need to build the migrations yourself.)
The syntax for nhmigrate is:
nhmigrate provider_name connection_string [to_version]
provider_name: The type of database. See below for permitted values.
connection_string: The database connection string.
to_version: The version to which to migrate the database. If omitted, the latest version will be selected.
Command Line Provider Names
nhmigrate supports the following values for the /p option:
Value | Database | Shortcut |
---|---|---|
MySql5 | MySQL | mysql |
Oracle9 | Oracle | oracle |
PostgreSql8 | PostgreSQL | pg |
Sqlite3 | SQLite | sqlite |
SqlServer2000 | Microsoft SQL Server 2000 | sql2000 |
SqlServer2005 | Microsoft SQL Server 2005/8 | sql |
SqlServerCE | Microsoft SQL Server Compact | sqlce |
VistaDB4 | VistaDB | vdb4 |
VistaDB3 | VistaDB (3.0 file format) | vdb3 |